﻿#ifndef GifAnimUI_h__
#define GifAnimUI_h__

#pragma once

namespace DuiLib {
class CControl;
class CGifInfo;
/*
class DUILIB_API CGifAnimUI : public CControlUI
{
public:
    CGifAnimUI(void);
    ~CGifAnimUI(void);

    LPCTSTR GetClass() const;
    LPVOID  GetInterface(LPCTSTR pstrName);
    void    DoInit() override;
    bool    DoPaint(HDC hDC, const RECT &rcPaint, CControlUI *pStopControl);
    void    DoEvent(TEventUI &event);
    void    SetVisible(bool bVisible = true);
    void    SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
    void    SetBkImage(LPCTSTR pStrImage);
    LPCTSTR GetBkImage();

    void    SetAutoPlay(bool bIsAuto = true);
    bool    IsAutoPlay() const;
    void    SetAutoSize(bool bIsAuto = true);
    bool    IsAutoSize() const;
    void    PlayGif();
    void    PauseGif();
    void    StopGif();

private:
    void    InitGifImage();
    void    DeleteGif();
    void    OnTimer(UINT_PTR idEvent);
    void    DrawFrame(HDC hDC);          // 绘制GIF每帧
    Gdiplus::Image *LoadGifFromFile(LPCTSTR pstrGifPath);
    Gdiplus::Image *LoadGifFromMemory(LPVOID pBuf, size_t dwSize);
private:
    Gdiplus::Image  *m_pGifImage;
    UINT            m_nFrameCount;              // gif图片总帧数
    UINT            m_nFramePosition;           // 当前放到第几帧
    Gdiplus::PropertyItem  *m_pPropertyItem;    // 帧与帧之间间隔时间

    CDuiString      m_sBkImage;
    bool            m_bIsAutoPlay;              // 是否自动播放gif
    bool            m_bIsAutoSize;              // 是否自动根据图片设置大小
    bool            m_bIsPlaying;

};
*/
class DUILIB_API CGifAnimUI : public CControlUI
{
public:
    CGifAnimUI(void);
    virtual ~CGifAnimUI(void) override;

    virtual LPCTSTR GetClass() const override;
    virtual LPVOID  GetInterface(LPCTSTR pstrName) override;
    virtual void    DoInit() override;
    virtual bool    DoPaint(HDC hDC, const RECT &rcPaint, CControlUI *pStopControl) override;
    virtual void    DoEvent(TEventUI &event) override;
    virtual bool    SetVisible(bool bVisible = true) override;
    virtual void    SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue) override;
    virtual void    SetBkImage(LPCTSTR pStrImage) override;

    void    SetAutoPlay(bool bIsAuto = true);
    bool    IsAutoPlay() const;
    void    SetAutoSize(bool bIsAuto = true);
    bool    IsAutoSize() const;
    void    PlayGif();
    void    PauseGif();
    void    StopGif();

private:
    void    InitGifImage();
    void    DeleteGif();
    void    OnTimer(UINT_PTR idEvent);
    void    DrawFrame(HDC hDC);                 // 绘制GIF当前帧
private:
    CGifInfo       *m_pcGifInfo;                // gif 图片信息

    bool            m_bIsAutoPlay;              // 是否自动播放gif
    bool            m_bIsAutoSize;              // 是否自动根据图片设置大小
    bool            m_bIsPlaying;
};

}

#endif // GifAnimUI_h__
